import { globalTimer } from './timer';
import { globalEventBus } from '../constant';

const g = globalThis as any;

if (!g.Buffer) {
  g.Buffer = {
    isBuffer() {
      return false;
    },
  };
}
if (typeof g.setTimeout === 'undefined') {
  g.setTimeout = globalTimer.setTimeout;
  g.clearTimeout = globalTimer.clearTimeout;
}
if (typeof g.setImmediate === 'undefined') {
  g.setImmediate = g.setTimeout;
  g.clearImmediate = g.clearTimeout;
}
if (typeof g.process === 'undefined') {
  g.process = {
    stderr: {},
    stdout: {},
    env: {},
  };
}

globalEventBus.on(
  'error',
  (err) => {
    console.error(err);
  },
  false
);
